package py.com.fms.converter;

import java.io.Serializable;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;

// Beans
import py.com.fms.gnd.bean.SymptomBean;
import py.com.fms.session.WithinHolder;

@Name("SymptomConverter")
public class SymptomConverter implements Converter, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2290513647958860985L;
	@Logger
	private Log log;
	
	
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		// TODO Auto-generated method stub
		if (arg2 != null) {
			try {
				WithinHolder holder = (WithinHolder)Component.getInstance(
						WithinHolder.class, true);
				if (holder == null) {
					return null;
				}
				SymptomBean bean = holder.symptomData(arg2);
//				System.out.println("print cod = " + bean.getCod());
				return bean;

			} catch (ConverterException e) {
				this.log.error(e);
			}
		}
		return null;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		// TODO Auto-generated method stub
		 if (arg2 instanceof SymptomBean) {
		     SymptomBean bean = (SymptomBean) arg2;
		     return bean.getDescrip();
		    }
		return null;
	}

}
